/*
 * Name: Minh-Tuan ta
 */

package data;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import beans.*;

public class PhotoDB extends ContentDB {
	public static synchronized ArrayList<Photo> getPhotosInAlbum(int albumID)
	{
		return convertContentsToPhotos(getContentOfExtraAndType(albumID, ContentTypeDB.getContentTypeID("Photo")));
	}
	
	public static synchronized Photo getPhoto(int photoID)
	{
		return convertContentToPhoto(getContent(photoID));
	}
	
	public static synchronized int createPhoto(Photo photo)
	{
		return addContent(photo);
	}
	
	public static synchronized int updatePhoto(Photo photo)
	{
		return updateContent(photo);
	}
	
	public static synchronized int deletePhoto(Photo photo, HttpServletRequest request)
	{
		Resource resource = ResourceDB.getResourceByContentID(photo.getContentID());
		
		if (ResourceDB.deleteResource(resource, request) != 0) //delete successfully
		{
			return deleteContent(photo);
		}
		else
			return 0;
	}
}
